<template>
	<view>
		<view class="scroll-view-container">
			<scroll-view scroll-y="true" :style="{height:wh+'px'}" class="left-scroll-view">
				<block v-for="(item,index) in cateList" :key='index'>
					<view :class="['left-scroll-view-item',index === active?'active':'']" @click="activeChange(index)">{{item.cat_name}}</view>
				</block>
				
				<!-- <view>11111</view> -->
			</scroll-view>
			
			<scroll-view scroll-y="true" :style="{height:wh+'px'}" class="right-scroll-view" :scroll-top="scrollTop">
				<view class="cate-two" v-for="(item2,index) in cateLeveTwo" :key='index'>
					<view class="cata-two-title">
						/{{item2.cat_name}}/
					</view>
					<view class="cate-level3-list" >
						<view class="cate-level3-item" v-for="(item3,index3) in item2.children" :key='index3' @click="goGoodsList(item3)">
							<image src="../../static/logo.png" mode=""></image>
							<text>{{item3.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		
	</view>
</template>

<script>
	import {categoriesData} from '@/api/cate_request.js';
	export default {
		data() {
			return {
				wh:0,
				cateList:[],
				active:0,
				cateLeveTwo:[],
				scrollTop:0
			};
		},
		methods:{
			async getCateList(){
				const {data:res} = await categoriesData();
				console.log(res);
				if(res.meta.status !== 200){
					return uni.showToast({
						title:'数据请求失败，请稍后',
						icon:'none'
					})
				};
				this.cateList = res.message;
				this.cateLeveTwo = res.message[0].children;
			},
			activeChange(index){
				this.active = index;
				this.cateLeveTwo = this.cateList[index].children;
				this.scrollTop = this.scrollTop === 0 ? 1:0;
			},
			goGoodsList(item3){
				uni.navigateTo({
					url:"/subpkg/goods-list/goods-list?cateId=" + item3.cat_id,
				})
			}
		},
		onLoad() {
			const sysInfo = uni.getSystemInfoSync();
			this.wh = sysInfo.windowHeight;
			this.getCateList();
		}
	}
</script>

<style lang="scss">
.scroll-view-container{
	display: flex;
	.left-scroll-view{
		width: 240rpx;
		.left-scroll-view-item{
			line-height: 120rpx;
			background-color: #f7f7f7;
			// color: #DD524D;
			text-align: center;
			&.active {
				background-color: #3F536E;
				position: relative;
				&::before{
					content: '';
					display: block;
					width: 10rpx;
					height: 30px;
					background-color: red;
					position: absolute;
					left: 0;
					top: 50%;
					transform:translateY(-50%)
					
				}
			}
		}
	}
	.right-scroll-view{
		.cate-two {
			.cata-two-title{
				font-size: 15px;
				font-weight: 700;
				text-align: center;
				padding: 15px 0;
			}
			.cate-level3-list {
				display: flex;
				flex-wrap: wrap;
				.cate-level3-item {
					width: 33.33%;
					display: flex;
					flex-direction: column;
					align-items: center;
					image{
						width: 120rpx;
						height: 120rpx;
					}
				}
			}
		}
	}
}
</style>
